package com.doctor.adapter;

import java.util.List;

import com.doctor.bean.OfficeBean;
import com.doctor.ui.R;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class OfficeAdapter extends BaseAdapter{

	/**
	 * 无纸办公要事提醒的adapter
	 */
	
	private Context context;
	private List<OfficeBean> beanList;
	
	public OfficeAdapter(Context context,List<OfficeBean> beanList){
		this.context=context;
		this.beanList=beanList;
	}
	
	public boolean addBean(OfficeBean bean){
		if (beanList.add(bean)) {
			return true;
		}
		return false;
	}
	
	public boolean removeBean(int index){
		 OfficeBean bean= beanList.remove(index);
		if (bean!=null) {
			this.notifyDataSetChanged();
			return true;
		}
		return false;
	}
	
	public void clear(){
		beanList.clear();
	}
	
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return beanList.size();
	}

	@Override
	public OfficeBean getItem(int arg0) {
		// TODO Auto-generated method stub
		return beanList.get(arg0);
	}

	@Override
	public long getItemId(int arg0) {
		// TODO Auto-generated method stub
		return arg0;
	}

	@Override
	public View getView(int arg0, View arg1, ViewGroup arg2) {
		// TODO Auto-generated method stub
		ViewHolder holder;
		if (arg1==null) {
			holder=new ViewHolder();
			arg1=View.inflate(context, R.layout.office_list_item, null);
			holder.date=(TextView) arg1.findViewById(R.id.date);
			holder.title=(TextView) arg1.findViewById(R.id.title);
			
			arg1.setTag(holder);
		} else {
			holder=(ViewHolder) arg1.getTag();
		}
		
		OfficeBean bean=getItem(arg0);
		
		holder.date.setText(bean.getDate());
		holder.title.setText(bean.getTitle());
		
		arg1.setTag(R.id.bean_tag, bean);
		
		return arg1;
	}
	
	private class ViewHolder{
		TextView date;
		TextView title;
	}

}
